/*
 * Copyright (C) 拾光分享网 
 * All rights reserved, Designed By www.hiai.top.
 * Email：goodsking@163.com.
 * Version：V1.0.2(20230701).
 */
package top.hiai.common.account;

import com.jfinal.plugin.activerecord.Db;

import top.hiai.common.model.User;

/**
 * @Author www.hiai.top
 * @Email goodsking@163.com
 * @Message 更多资源尽在www.hiai.top
 * @Introduction 类的介绍:用户发帖规则
 */

public class UserRoleService {

    public static final UserRoleService me = new UserRoleService();

    /**
     * 发表一个文章获取的积分
     */
    public static final int ADD_ARTICLE = 5;
    /**
     * 发表一个评论获取的积分
     */
    public static final int ADD_REPLY = 1;
    /**
     * 违规将扣除的积分
     */
    public static final int WEI_GUI = 10;

    /**
     * 给用户添加积分
     *
     * @param uid
     * @return
     */
    public int setAddUserPoints(int points, int uid) {
        return Db.update(" update bbs_user set points=points+? where uid=? ", points, uid);
    }

    /**
     * 减少用户的积分
     * 先判断用户的积分是否够用户
     *
     * @param uid
     * @return
     */
    public boolean setCutUserPoints(int points, int uid) {
        User user = UserService.me.getById(uid);
        int temp = user.getPoints();
        if (temp < points) {
            return false;
        } else {
            Db.update(" update bbs_user set points=points-? where uid=? ", points, uid);
            return true;
        }
    }
}